//
//  HTProfile.swift
//  MagaCore
//
//  Created by 罗林轩 on 2024/8/30.
//  Copyright © 2024 HT. All rights reserved.
//

import SwiftUI

/// 容器
/// - Parameter model: 入参model
/// - Returns:
@ViewBuilder func itemConent(model: HTProfileItemViewModel) -> some View {
    VStack {
        HStack {
            Text(model.type.rawValue)
                .ht_commonTextStyle(color: Color(hex: "#393939"), fontSize: 14, weight: .medium)
                .padding(.top, 20)
                .padding(.bottom, 20)
            Spacer()
            if  model.type == .protrait {
                Image("library_default_avatar")
            } else if  model.type == .email {
                Button {
                    model.clickCallBack()
                } label: {
                    Text (model.content)
                }
            } else if  model.type == .nickname  || model.type == .gender  || model.type == .brithday {
                Button {
                    model.clickCallBack()
                } label: {
                    HStack {
                        Text (model.content)
                        Image("arrow_right")
                    }
                }
            } else {
                Button {
                    model.clickCallBack()
                } label: {
                    HStack {
                        Image("arrow_right")
                    }
                }
            }
        }
        .padding(.horizontal, 15)
        Divider()
            .padding(.leading,10)
    }
}

struct HTProfileView: View {
    @ObservedObject var model: HTProfileViewViewModel = HTProfileViewViewModel()

    var body: some View {
        HTNavigationBar {
            ScrollView {
                VStack {
                    ForEach(model.items, id: \.self.type) { item in
                        itemConent(model: item)
                    }

                    Text("Sign Out")
                        .frame(width: 200, height: 36)
                        .foregroundStyle(.white)
                        .background(Color(hex: "fc0b52"))
                        .cornerRadius(18, corners: .allCorners)
                        .padding(.top,50)
                }
            }
            .toolbar(.hidden, for: .bottomBar)
            .onAppear {
            }
        }
        .ht_title(title: "Profile")
    }
}

#Preview {
    HTProfileView()
}
